﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LogViewApp.ViewModel;

namespace LogViewApp.ViewModel
{
    public class ViewModelLocator
    {
        private static HomeViewModel _homeViewModel;
        private static Dictionary<string, LogViewModel> _logViewModelDict;
        //private static LogViewModel _logViewModel;
        /// <summary>
        /// Initializes a new instance of the ViewModelLocator class.
        /// </summary>
        public ViewModelLocator()
        {
            _logViewModelDict = new Dictionary<string, LogViewModel>();
        }

        public HomeViewModel homeViewModel
        {
            get
            {
                if (_homeViewModel == null)
                {
                    _homeViewModel = new HomeViewModel();

                }
                return _homeViewModel;
            }
        }

        /// <summary>
        /// Cleans up all the resources.
        /// </summary>
        public static void Dispose()
        {
            _homeViewModel.Dispose();
            _homeViewModel = null;
            foreach (KeyValuePair<string, LogViewModel> kvp in _logViewModelDict)
            {
                kvp.Value.Dispose();
            }
            _logViewModelDict = null;
        }


        internal LogViewModel GetLogViewModel(string guidString)
        {
            if (_logViewModelDict.ContainsKey(guidString))
            {
                return _logViewModelDict[guidString];
            }
            else
            {
                LogViewModel logViewModel = new LogViewModel();
                _logViewModelDict.Add(guidString, logViewModel);
                return logViewModel;
            }
        }
    }
}
